package com.young.core.domain;

import java.io.Serializable;
import java.util.Date;

/**
 * 任务追踪，记录表
 */
public class TraceDO implements Serializable {

    private int id;
    private String project;
    private String name;
    private int jobId;
    private String clazz;
    private String method;
    //业务回传的data数据
    private String data;
    private String uniqueCode;
    private String traceId;

    private long duration;

    private String triggerNode;

    //分片数量
    //广播分片时，节点数量、索引
    private int total = 1;

    private int sc;//成功计数器，如果sc == total表示此任务已完结
    private transient boolean success = false;
    private Date createTime;
    private Date updateTime;

    /**
     * 结构：
     * {"0":[
     *      {"address":"12.1.1.1:8080","status":"0","time"},
     *      {"address":"12.1.1.1:8080","status":"1"}
     *      ]
     *  "1":[
     *      {"address":"12.1.1.2:8080","status":"0"},
     *      {"address":"12.1.1.3:8080","status":"1"}
     * }
     */
    private String content;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getJobId() {
        return jobId;
    }

    public void setJobId(int jobId) {
        this.jobId = jobId;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUniqueCode() {
        return uniqueCode;
    }

    public void setUniqueCode(String uniqueCode) {
        this.uniqueCode = uniqueCode;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getTriggerNode() {
        return triggerNode;
    }

    public void setTriggerNode(String triggerNode) {
        this.triggerNode = triggerNode;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public int getSc() {
        return sc;
    }

    public void setSc(int sc) {
        this.sc = sc;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    /**
     * 过程，每个节点执行的结果，包括失败重试等
     */
    public static class NodeTrace implements Serializable {

        private String ip;
        private int port;
        private int index;
        private int status;//此节点执行的状态
        private Date time;
        private int retryNumber = 0;//第几次重试
        private String message;//消息
        private long duration;//执行时间
        private String data;//回传数据

        public String getIp() {
            return ip;
        }

        public void setIp(String ip) {
            this.ip = ip;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public Date getTime() {
            return time;
        }

        public void setTime(Date time) {
            this.time = time;
        }

        public int getRetryNumber() {
            return retryNumber;
        }

        public void setRetryNumber(int retryNumber) {
            this.retryNumber = retryNumber;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public long getDuration() {
            return duration;
        }

        public void setDuration(long duration) {
            this.duration = duration;
        }

        public String getData() {
            return data;
        }

        public void setData(String data) {
            this.data = data;
        }
    }
}
